WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
state_quaternion.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
23
24namespace wolf
25{
27{
28 public:
29 StateQuaternion(bool _fixed = false, bool _transformable = true);
30 StateQuaternion(const Eigen::VectorXd& _state, bool _fixed = false, bool _transformable = true);
31 StateQuaternion(const Eigen::Quaterniond& _quaternion, bool _fixed = false, bool _transformable = true);
32 ~StateQuaternion() override;
33 static Eigen::VectorXd Identity();
35
36 void setIdentity(bool _notify = true) override;
37 Eigen::VectorXd identity() const override;
38
39 virtual void transform(const VectorComposite& _transformation) override;
40};
41
42inline StateQuaternion::StateQuaternion(const Eigen::Quaterniond& _quaternion, bool _fixed, bool _transformable)
43 : StateBlock("StateQuaternion",
44 _quaternion.coeffs(),
45 _fixed,
47 _transformable)
48{
49 state_.normalize();
50}
51
52inline StateQuaternion::StateQuaternion(const Eigen::VectorXd& _state, bool _fixed, bool _transformable)
53 : StateBlock("StateQuaternion",
54 _state,
55 _fixed,
57 _transformable)
58{
59 if (state_.size() != 4) throw std::runtime_error("The quaternion state vector must be of size 4!");
60
61 state_.normalize();
62}
63
64inline StateQuaternion::StateQuaternion(bool _fixed, bool _transformable)
65 : StateBlock("StateQuaternion",
66 4,
67 _fixed,
69 _transformable)
70{
71 state_ = Eigen::Quaterniond::Identity().coeffs();
72}
73
75
76inline void StateQuaternion::setIdentity(bool _notify)
77{
78 setState(Eigen::Quaterniond::Identity().coeffs(), _notify);
79}
80
81inline Eigen::VectorXd StateQuaternion::Identity()
82{
83 return Eigen::Quaterniond::Identity().coeffs();
84}
85
86inline Eigen::VectorXd StateQuaternion::identity() const
87{
88 return Eigen::Quaterniond::Identity().coeffs();
89}
90
91inline void StateQuaternion::transform(const VectorComposite& _transformation)
92{
95 (Eigen::Quaterniond(_transformation.at('O').data()) * Eigen::Quaterniond(getState().data())).coeffs());
96}
97
98} // namespace wolf
Local parametrization for quaternions.
Definition: local_parametrization_quaternion.h:54
class StateBlock
Definition: state_block.h:73
bool transformable_
Flag to indicate if the state block can be transformed to another reference frame.
Definition: state_block.h:91
void setState(const Eigen::VectorXd &_state, const bool _notify=true)
Sets the state vector.
Definition: state_block.cpp:25
Eigen::VectorXd getState() const
Returns the state vector.
Definition: state_block.h:296
Eigen::VectorXd state_
State vector storing the state values.
Definition: state_block.h:80
Definition: state_quaternion.h:27
~StateQuaternion() override
Definition: state_quaternion.h:74
WOLF_STATE_BLOCK_CREATE(StateQuaternion)
static Eigen::VectorXd Identity()
Definition: state_quaternion.h:81
void setIdentity(bool _notify=true) override
Definition: state_quaternion.h:76
virtual void transform(const VectorComposite &_transformation) override
Definition: state_quaternion.h:91
Eigen::VectorXd identity() const override
Definition: state_quaternion.h:86
StateQuaternion(bool _fixed=false, bool _transformable=true)
Definition: state_quaternion.h:64
Definition: vector_composite.h:27
Definition: jet.h:1355
Definition: capture_base.h:23
@ DQ_LOCAL
Definition: local_parametrization_quaternion.h:36